'use strict'
let fs = require('fs');
let { sequelize } = require('../dbConnection/creatModels');

function findFiles() {
    let files = fs.readdirSync(__dirname)
    return files.filter(x => {
        return x.endsWith('.js') && x !== 'm_index.js'
    })
}

function reModels(files) {
    let obj = {}
    files.forEach(element => {
        let key = element.substring(0, element.length - 3)
        obj[key] = require(__dirname + '/' + element)
    });
    return obj
}

let files = findFiles();
let obj = reModels(files);

obj.sync = async() => {
    if (process.env === 'product') {
        console.log('不可强制更改或删除表');
    } else {
        return sequelize.sync({ force: true });
    }
}

module.exports = obj;